package com.encryption.util.mail.sender;

import com.encryption.util.ConfigProperties;

/**
 * 发送邮件
 * 
 * @author Administrator
 * 
 */
public class MailSend {
	/**
	 * 发送文本邮件
	 * 
	 * @param fromAddress
	 * @param toAddress
	 * @param title
	 * @param txtContent
	 * @return
	 */
	public static boolean sendTextMail(String toAddress, String title,
			String txtContent) {
		// 这个类主要是设置邮件
		MailSenderInfo mailInfo = new MailSenderInfo();
		mailInfo.setMailServerHost(ConfigProperties
				.getProperty("mail.server.host"));
		mailInfo.setMailServerPort(ConfigProperties
				.getProperty("mail.server.port"));
		String fromAddress = ConfigProperties.getProperty("mail.account");
		mailInfo.setValidate(true);
		mailInfo.setUserName(ConfigProperties.getProperty("mail.userName"));
		mailInfo.setPassword(ConfigProperties.getProperty("mail.password"));// 您的邮箱密码
		mailInfo.setFromAddress(fromAddress);
		mailInfo.setToAddress(toAddress);
		mailInfo.setSubject(title);

		mailInfo.setContent(txtContent);
		// 这个类主要来发送邮件
		SimpleMailSender sms = new SimpleMailSender();
		return sms.sendTextMail(mailInfo);// 发送文体格式

	}

	/**
	 * 发送html格式的邮件
	 * 
	 * @param fromAddress
	 * @param toAddress
	 * @param title
	 * @param htmlContent
	 * @return
	 */
	public static boolean sendHtmlMail(String toAddress, String title,
			String htmlContent) {
		// 这个类主要是设置邮件
		MailSenderInfo mailInfo = new MailSenderInfo();
		mailInfo.setMailServerHost(ConfigProperties
				.getProperty("mail.server.host"));
		mailInfo.setMailServerPort(ConfigProperties
				.getProperty("mail.server.port"));
		String fromAddress = ConfigProperties.getProperty("mail.account");
		mailInfo.setValidate(true);
		mailInfo.setUserName(ConfigProperties.getProperty("mail.userName"));
		mailInfo.setPassword(ConfigProperties.getProperty("mail.password"));// 您的邮箱密码
		mailInfo.setFromAddress(fromAddress);
		mailInfo.setToAddress(toAddress);
		mailInfo.setSubject(title);
		mailInfo.setContent(htmlContent);

		// 这个类主要来发送邮件
		SimpleMailSender sms = new SimpleMailSender();
		return sms.sendHtmlMail(mailInfo);// 发送html格式
	}

	public static void main(String[] args) {
		boolean isSuccess = sendTextMail("270210858@qq.com", "验证码",
				"验证码为123456");
		System.out.println(isSuccess);
	}

}
